package com.grantheath.erebus.model 
{
	import com.grantheath.erebus.model.enum.notifications.ErebusInitializationNotifications;
	import com.grantheath.erebus.model.loaders.ErebusXMLAssetLoader;
	import com.grantheath.erebus.model.loaders.ErebusFontAssetLoader;
	import com.grantheath.erebus.model.loaders.ErebusCSSAssetLoader;
	import com.grantheath.erebus.model.loaders.ErebusTextAssetLoader;
	import com.grantheath.erebus.model.loaders.ErebusByteArrayAssetLoader;
	import com.grantheath.erebus.model.loaders.ErebusDisplayObjectAssetLoader;
	import com.grantheath.erebus.model.enum.names.ErebusAssetTypes;
	import com.grantheath.erebus.model.enum.names.ErebusProxyNames;
	import com.grantheath.erebus.model.interfaces.IErebusAssetLoaderClassReferenceProxy;

	import org.puremvc.as3.patterns.proxy.Proxy;

	/**
	 * @author grantheath
	 */
	public class ErebusAssetLoaderClassReferenceProxy extends Proxy implements IErebusAssetLoaderClassReferenceProxy 
	{
		public function ErebusAssetLoaderClassReferenceProxy()
		{
			super(ErebusProxyNames.ASSET_LOADER_CLASS_REFERENCE_PROXY);
		}

		override public function onRegister() : void
		{
			sendNotification(ErebusInitializationNotifications.INITIALIZE_PROXIES);
		}

		public function getAssetLoaderClassFromType(type : String) : Class
		{
			var assetLoaderClass : Class;
			
			if(type == ErebusAssetTypes.BYTE_ARRAY_ASSET) {
				assetLoaderClass = ErebusByteArrayAssetLoader;
			} else if(type == ErebusAssetTypes.CSS_ASSET) {
				assetLoaderClass = ErebusCSSAssetLoader;
			} else if(type == ErebusAssetTypes.DISPLAY_OBJECT_ASSET) {
				assetLoaderClass = ErebusDisplayObjectAssetLoader;
			} else if(type == ErebusAssetTypes.FONT_ASSET) {
				assetLoaderClass = ErebusFontAssetLoader;
			} else if(type == ErebusAssetTypes.TEXT_ASSET) {
				assetLoaderClass = ErebusTextAssetLoader;
			} else if(type == ErebusAssetTypes.XML_ASSET) {
				assetLoaderClass = ErebusXMLAssetLoader;
			}
			return assetLoaderClass;
		}

		public function getAssetLoaderClassFromExtension(fileName : String) : Class
		{
			var splitFilename : Array = fileName.split(".");
			var extension : String;
			var assetLoaderClass : Class = ErebusByteArrayAssetLoader;
			
			if(splitFilename.length > 0) {
				extension = String(splitFilename[splitFilename.length - 1]).toLowerCase();
				
				if(extension == "jpg") {
					assetLoaderClass = ErebusDisplayObjectAssetLoader;
				} else if(extension == "png"){
					assetLoaderClass = ErebusDisplayObjectAssetLoader;
				} else if(extension == "gif"){
					assetLoaderClass = ErebusDisplayObjectAssetLoader;
				} else if(extension == "swf"){
					assetLoaderClass = ErebusDisplayObjectAssetLoader;
				} else if(extension == "txt") {
					assetLoaderClass = ErebusTextAssetLoader;
				} else if(extension == "css") {
					assetLoaderClass = ErebusCSSAssetLoader;
				} else if(extension == "fnt") {
					assetLoaderClass = ErebusFontAssetLoader;
				} else if(extension == "xml") {
					assetLoaderClass = ErebusXMLAssetLoader;
				}
			}
			return assetLoaderClass;
		}
	}
}
